package com.example.demo.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.anotation.ControllerLog;
import com.example.demo.entity.User;
import com.example.demo.service.IUserService;
import com.example.demo.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author mybatis-plus-generator
 * @since 2022-06-25
 */
@Api("user接口")
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @ApiOperation("添加用户")
    @ControllerLog("添加用户")
    @PostMapping("add")
    public R addUser(@RequestBody User param) {
        param.setIsDeleted(false);
        userService.save(param);
        return R.ok();
    }

    @ApiOperation("删除用户")
    @ControllerLog("删除用户")
    @GetMapping("delete")
    public R deleteUser(@RequestParam Integer id) {
        userService.removeById(id);
        return R.ok();
    }

    @ApiOperation("更新用户")
    @ControllerLog("更新用户")
    @PostMapping("update")
    public R deleteUser(@RequestBody @Valid User param) {
        userService.updateById(param);
        return R.ok();
    }

    @ApiOperation("分页查询用户")
    @ControllerLog("分页查询用户")
    @PostMapping("page-list")
    public R pageList(@RequestBody @Valid User param) {
        Page<User> ret = userService.pageList(param);
        return R.ok(ret);
    }
}

